package com.itheima;

import com.alibaba.druid.pool.DruidDataSource;
import com.itheima.config.serverConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableConfigurationProperties(serverConfig.class)//将使用配置注入的类加入到spring容器中，这样更明了的知道那个类使用了配置注入
public class ConfigurationPropertitesApplication {

    @Bean
    //配置文件大小写-随便写，最后匹配的时候会将所有的字母都转为小写，然后-都会忽略掉
    @ConfigurationProperties(prefix = "d-a-t-a-s-o-urce")
    public DruidDataSource dataSource(){
        DruidDataSource ds = new DruidDataSource();
        return ds;
    }

    public static void main(String[] args) {
        ConfigurableApplicationContext ioc = SpringApplication.run(ConfigurationPropertitesApplication.class, args);
        serverConfig bean = ioc.getBean(serverConfig.class);
        System.out.println(bean.getTimeout());
//        System.out.println(bean.getDataSize());

        DruidDataSource bean1 = ioc.getBean(DruidDataSource.class);
        System.out.println(bean1.getDriverClassName());

    }
}
